<?
function news_source($link){
	
	$site_name	= "";
	$link			= strtolower($link);
	
	//Kiểm tra xem tin lấy thuộc site nào
	if(strpos($link,"24h.com.vn") !== false)	 			$site_name = "24h.com.vn";
	elseif(strpos($link,"autonet.com.vn") !== false)	$site_name = "AutoNet.com.vn";
	elseif(strpos($link,"autopro.channelvn.net") !== false)	$site_name = "AutoPro.ChannelVN.net";
	elseif(strpos($link,"bongda.com.vn") !== false)		$site_name = "BongDa.com.vn";
	elseif(strpos($link,"bongdaso.com") !== false)		$site_name = "BongDaSo.com";
	elseif(strpos($link,"cand.com.vn") !== false)		$site_name = "CAND.com.vn";
	elseif(strpos($link,"thethao.dantri.com.vn") !== false)	$site_name = "TheThao.DanTri.com.vn";
	elseif(strpos($link,"dantri.com.vn") !== false)		$site_name = "DanTri.com.vn";
	elseif(strpos($link,"dothi.net") !== false) 			$site_name = "DoThi.net";
	elseif(strpos($link,"dothi.vnexpress.net") !== false) 	$site_name = "DoThi.net";
	elseif(strpos($link,"giadinh.net.vn") !== false) 	$site_name = "GiaDinh.net.vn";
	elseif(strpos($link,"kenh14.vn") !== false) 			$site_name = "Kenh14.vn";
	elseif(strpos($link,"muctim.com.vn") !== false) 	$site_name = "MucTim.com.vn";
	elseif(strpos($link,"ngoisao.net") !== false) 		$site_name = "NgoiSao.net";
	elseif(strpos($link,"ngoisao.vnexpress.net") !== false) 	$site_name = "NgoiSao.net";
	elseif(strpos($link,"nguoihammo.vn") !== false) 	$site_name = "TheThao.VietNamNet.vn";
	elseif(strpos($link,"nld.com.vn") !== false) 		$site_name = "NLD.com.vn";
	elseif(strpos($link,"sohoa.net") !== false)			$site_name = "SoHoa.net";
	elseif(strpos($link,"sohoa.vnexpress.net") !== false)		$site_name = "SoHoa.net";
	elseif(strpos($link,"thanhnien.com.vn") !== false)	$site_name = "ThanhNien.com.vn";
	elseif(strpos($link,"thegioioto.com.vn") !== false)$site_name = "TheGioiOto.com.vn";
	elseif(strpos($link,"tienphong.vn") !== false)		$site_name = "TienPhong.vn";
	elseif(strpos($link,"timnhanh.com") !== false)		$site_name = "TimNhanh.com";
	elseif(strpos($link,"tintuconline") !== false)		$site_name = "TinTucOnline.com";
	elseif(strpos($link,"tuoitre.com.vn") !== false)	$site_name = "TuoiTre.com.vn";
	elseif(strpos($link,"thethao.vietnamnet.vn") !== false)	$site_name = "TheThao.VietNamNet.vn";
	elseif(strpos($link,"vietnamnet.vn") !== false)		$site_name = "VietNamNet.vn";
	elseif(strpos($link,"vnexpress.net") !== false)		$site_name = "vnExpress.net";
	elseif(strpos($link,"vnmedia.vn") !== false)			$site_name = "vnMedia.vn";
	elseif(strpos($link,"vtc.vn") !== false)				$site_name = "VTC.vn";
	else $site_name = "Internet";
	
	//Trả về nguồn tin
	return $site_name;
	
}
?>
<?
function news_update_source($update, $link){
	$strReturn	= tdt("Cap_nhat") . ': ' . $update . ' - <script type="text/javascript">news_source(' . write_source_js($link) . ');</script>';
	return $strReturn;
}
?>
<?
function newsSource($link){
	
	$imageFolder= "images_unknow";
	$link			= strtolower($link);
	
	$array_link	= array ("24h.com.vn"				=> "24h",
								"autonet.com.vn"			=> "autonet",
								"autopro.channelvn.net"	=> "autopro",
								"bongda.com.vn"			=> "bongda",
								"bongdaso.com"				=> "bongdaso",
								"cand.com.vn"				=> "cand",
								"dantri.com.vn"			=> "dantri",
								"dothi.net"					=> "dothi",
								"dothi.vnexpress.net"	=> "dothi",
								"giadinh.net.vn"			=> "giadinh",
								"kenh14.vn"					=> "kenh14",
								"muctim.com.vn"			=> "muctim",
								"ngoisao.net"				=> "ngoisao",
								"ngoisao.vnexpress.net"	=> "ngoisao",
								"nguoihammo.vn"			=> "thethao.vietnamnet",
								"nld.com.vn"				=> "nld",
								"sohoa.net"					=> "sohoa",
								"sohoa.vnexpress.net"	=> "sohoa",
								"thanhnien.com.vn"		=> "thanhnien",
								"thegioioto.com.vn"		=> "thegioioto",
								"thethao.vietnamnet.vn"	=> "thethao.vietnamnet",
								"tienphong.vn"				=> "tienphong",
								"timnhanh.com"				=> "timnhanh",
								"tintuconline.com.vn"	=> "tintuconline",
								//"tintuconline"				=> "tintuconline.vietnamnet",
								"tuoitre.com.vn"			=> "tuoitre",
								"vietnamnet.vn"			=> "vietnamnet",
								"vnexpress.net"			=> "vnexpress",
								"vnmedia.vn"				=> "vnmedia",
								"vtc.vn"						=> "vtc",
								);
	foreach($array_link as $key => $value){
		if(strpos($link, $key) !== false){
			$imageFolder = $value;
			break;
		}
	}
	
	return $imageFolder;
	
}
?>
<?
function send_request($url_get_news, $iAcc, $iKey, $iNew, $status){
	// Kiểm tra nếu server có hỗ trợ http_build_query (PHP >= 5) thì dùng method POST để xóa account_queue
	if(function_exists("http_build_query")){
		//Thiết lập những tham số để post
		$postdata = http_build_query(
			 array(
				  'iAcc'		=> $iAcc,
				  'iKey'		=> $iKey,
				  'iNew'		=> $iNew,
				  'status'	=> $status
			 )
		);
		
		$headers  = 'Content-type: application/x-www-form-urlencoded' . "\r\n";
		$headers .= 'Content-Length: ' . strlen($postdata) . "\r\n";
	
		$context_options	= array ('http' => array('method'	=> 'POST',
																 'header'	=> $headers,
																 'content'	=> $postdata
																 )
											);
		
		$context	= stream_context_create($context_options);
		$result	= file_get_contents($url_get_news, false, $context);
	}
	// Ngược lại thì dùng method GET để xóa
	else{
		$url_get_news .= "?iAcc=" . $iAcc . "&iKey=" . $iKey . "&iNew=" . $iNew . "&status=" . $status;
		$result	= file_get_contents($url_get_news, false);
	}
}
?>
<?
function remove_teaser($value, $source){
	$array_replace = array();
	switch($source){
		case "autopro":
			$array_replace	= array ('(AutoPro)- ', '(AutoPro) - ');
			break;
		case "dantri":
			$array_replace	= array ('(Dân trí) - ');
			break;
		case "giadinh":
			$array_replace	= array ('Giadinh.net - ');
			break;
		case "kenh14":
			$array_replace	= array ('[Kênh14] - ', '[Kênh14] – ', '[Kênh14]- ', '[Kênh 14] - ', '[Kênh 14]- ');
			break;
		case "thanhnien":
			$array_replace	= array ('(TNO) ');
			break;
		case "thegioioto":
			$array_replace	= array ('(thegioioto) ', '(thegioioto)');
			break;
		case "tienphong":
			$array_replace	= array ('TPO - ', 'TP- ', 'TP - ', 'TPO – ');
			break;
		case "thethao.vietnamnet":
		case "vietnamnet":
			$array_replace	= array ('(VietNamNet) - ');
			break;
		case "vnmedia":
			$array_replace	= array ('(VnMedia) - ');
			break;
	}
	$value	= str_replace($array_replace, "", $value);
	return $value;
}
?>
<?
function remove_description($value, $source=""){

	$array_replace = array();
	switch($source){
		case "24h":
			$array_replace	= array ('<TR>
<TD align=middle width="100%">
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=center align=left height=18></TD>
<TD class=Copy vAlign=center align=right height=18>&nbsp; </TD></TR></TBODY></TABLE></TD></TR>',
											);
			break;
		case "autopro":
			$array_replace	= array ('(AutoPro)- ', '(AutoPro) - ', ' width="100%"');
			break;
		case "bongda":
			$array_replace	= array ('Đánh giá(?):',
											'<DIV style="CLEAR: both; HEIGHT: 10px"></DIV>',
											'<BR>
<DIV><B class=aritlceTitle></B></DIV>',
											);
			break;
		case "bongdaso":
			$array_replace	= array ("<TR>
<TD width=5>&nbsp;</TD>
<TD width=5>&nbsp;</TD></TR>
<TR>",
											"Các tin khác:",
											);
			break;
		case "dantri":
	$array_replace = array ("<P></P>",
									"(Dân trí) - ",
									"<TR>
<TD><!-- begin baamboo --><BR><BR><!-- end baamboo --></TD></TR>
<TR class=event></TR>",
									);
			break;
		case "giadinh":
			$array_replace	= array ('Giadinh.net - ');
			break;
		case "kenh14":
			$array_replace	= array ('<BR>
<DIV style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; PADDING-BOTTOM: 10px; PADDING-TOP: 10px"></DIV>',
											'<BR style="LINE-HEIGHT: 20px; HEIGHT: 10px"><BR style="HEIGHT: 10px"><B></B>',
											'[Kênh 14] - ',
											'[Kênh 14]- ',
											'[Kênh14] – ',
											'[Kênh14]- ',
											' style="PADDING-LEFT: 5px; VERTICAL-ALIGN: top"',
											);
			break;
		case "muctim":
			$array_replace	= array (' cellSpacing=0 cellPadding=0 width=424 border=0',
											'<TR>
<TD align=left>&nbsp;</TD></TR>
<TR>
<TD height=10>&nbsp;</TD></TR>',
											' cellSpacing=2 cellPadding=2',
											' class=Detail-Lead id=eLead style="MARGIN-TOP: 20px"',
											'<P align=justify><B></B>&nbsp; 
<P align=justify><B></B>&nbsp; ');
			break;
		case "thanhnien":
			$array_replace	= array ('(TNO) ');
			break;
		case "thegioioto":
			$array_replace	= array ('(<FONT color=limegreen>thegioioto</FONT>) ', '(<FONT color=limegreen>thegioioto</FONT>)');
			break;
		case "tienphong":
			$array_replace	= array ('TPO - ', 'TP- ', 'TP - ', 'TPO – ', ' onclick="return showImage(this.src)"');
			break;
		case "tintuconline.vietnamnet":
			$array_replace	= array (" onclick='return openNewImage(this.src)'");
			break;
		case "thethao.vietnamnet":
		case "vietnamnet":
			$array_replace	= array ('(VietNamNet) - ');
			break;
		case "vnexpress":
			$array_replace	= array (' style="FLOAT: left; WIDTH: 490px"', ' width="100%"');
			break;
		case "vnmedia":
			$array_replace	= array ('(VnMedia)- ', '(VnMedia) - ', '(VnMedia) -', '(VnMedia)', ' width="95%"');
			break;
		case "vtc":
			$array_replace	= array ('class=Content');
			break;
	}
	$value = str_replace($array_replace, "", $value);
	return $value;
	
}
?>
<?
function write_source_js($link){
	$source	= 0;
	$link		= strtolower($link);
	
	//Kiểm tra xem tin lấy thuộc site nào
	if(strpos($link,"24h.com.vn") !== false)	 			$source = 1;
	elseif(strpos($link,"bongda.com.vn") !== false)		$source = 2;
	elseif(strpos($link,"bongdaso.com") !== false)		$source = 3;
	elseif(strpos($link,"cand.com.vn") !== false)		$source = 4;
	elseif(strpos($link,"thethao.dantri.com.vn") !== false)	$source = 5;
	elseif(strpos($link,"dantri.com.vn") !== false)		$source = 6;
	elseif(strpos($link,"dothi.net") !== false) 			$source = 7;
	elseif(strpos($link,"dothi.vnexpress.net") !== false) 	$source = 7;
	elseif(strpos($link,"giadinh.net.vn") !== false) 	$source = 8;
	elseif(strpos($link,"ngoisao.net") !== false) 		$source = 9;
	elseif(strpos($link,"ngoisao.vnexpress.net") !== false) 	$source = 9;
	elseif(strpos($link,"nguoihammo.vn") !== false) 	$source = 10;
	elseif(strpos($link,"nld.com.vn") !== false) 		$source = 11;
	elseif(strpos($link,"sohoa.net") !== false)			$source = 12;
	elseif(strpos($link,"sohoa.vnexpress.net") !== false)		$source = 12;
	elseif(strpos($link,"thanhnien.com.vn") !== false)	$source = 13;
	elseif(strpos($link,"tienphong.vn") !== false)		$source = 14;
	elseif(strpos($link,"timnhanh.com") !== false)		$source = 15;
	elseif(strpos($link,"tintuconline") !== false)		$source = 16;
	elseif(strpos($link,"tuoitre.com.vn") !== false)	$source = 17;
	elseif(strpos($link,"thethao.vietnamnet.vn") !== false)	$source = 18;
	elseif(strpos($link,"vietnamnet.vn") !== false)		$source = 19;
	elseif(strpos($link,"vnexpress.net") !== false)		$source = 20;
	elseif(strpos($link,"vnmedia.vn") !== false)			$source = 21;
	elseif(strpos($link,"vtc.vn") !== false)				$source = 22;
	elseif(strpos($link,"kenh14.vn") !== false)			$source = 23;
	elseif(strpos($link,"muctim.com.vn") !== false)		$source = 24;
	elseif(strpos($link,"autonet.com.vn") !== false)	$source = 25;
	elseif(strpos($link,"autopro.channelvn.net") !== false)	$source = 26;
	elseif(strpos($link,"thegioioto.com.vn") !== false)$source = 27;
	
	//Trả về nguồn tin
	return $source;
}
?>